package com.xinye.opencvdemo.utils

import android.widget.Toast
import androidx.annotation.StringRes
import com.xinye.opencvdemo.AppApplication

/**
 * Toast工具
 *
 * @author wangheng
 */
object ToastUtils {
    fun toastShort(text: String?){
        if(text == null || text.trim().isEmpty()){
            return
        }
        toast(text,false)
    }

    fun toastShort(@StringRes textId: Int){
        toastShort(AppApplication.getAppContext().getString(textId))
    }

    fun toastLong(text: String?){
        if(text == null || text.trim().isEmpty()){
            return
        }
        toast(text,true)
    }
    fun toastLong(@StringRes textId: Int){
        toastLong(AppApplication.getAppContext().getString(textId))
    }

    private fun toast(text: String,isLong: Boolean = false){
        val duration = if(isLong){
            Toast.LENGTH_LONG
        }else{
            Toast.LENGTH_SHORT
        }
        Toast.makeText(AppApplication.getAppContext(),text,duration).show()
    }
}